
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Webpack · introduce</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="Gj">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-prism/prism-tomorrow.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
        <link rel="stylesheet" href="../index.css">
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="router.html" />
    
    
    <link rel="prev" href="jsdoc.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    引导
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="vscode.html">
            
                <a href="vscode.html">
            
                    
                    Vscode
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="jsdoc.html">
            
                <a href="jsdoc.html">
            
                    
                    Jsdoc
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.4" data-path="webpack.html">
            
                <a href="webpack.html">
            
                    
                    Webpack
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="router.html">
            
                <a href="router.html">
            
                    
                    路由和侧边栏
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="env.html">
            
                <a href="env.html">
            
                    
                    环境变量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="cors.html">
            
                <a href="cors.html">
            
                    
                    跨域问题
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="router-lazyload.html">
            
                <a href="router-lazyload.html">
            
                    
                    路由懒加载
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="icons.html">
            
                <a href="icons.html">
            
                    
                    图标
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="i18n.html">
            
                <a href="i18n.html">
            
                    
                    国际化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="eslint.html">
            
                <a href="eslint.html">
            
                    
                    ESLint
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="permission.html">
            
                <a href="permission.html">
            
                    
                    权限验证
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="style.html">
            
                <a href="style.html">
            
                    
                    样式
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >Webpack</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="webpack&#x76F8;&#x5173;&#x914D;&#x7F6E;">Webpack&#x76F8;&#x5173;&#x914D;&#x7F6E;</h1>
<blockquote>
<p>&#x7F16;&#x8BD1;&#x3001;&#x6253;&#x5305;&#x3001;&#x914D;&#x7F6E;&#x73AF;&#x5883;&#x53D8;&#x91CF;</p>
<p>&#x8BE6;&#x7EC6;&#x6587;&#x6863;&#x67E5;&#x9605; <a href="https://cli.vuejs.org/zh/guide/mode-and-env.html" target="_blank">https://cli.vuejs.org/zh/guide/mode-and-env.html</a></p>
</blockquote>
<h4 id="&#x914D;&#x7F6E;&#x6587;&#x4EF6;">&#x914D;&#x7F6E;&#x6587;&#x4EF6;</h4>
<blockquote>
<p>.env &#x5168;&#x5C40;&#x53D8;&#x91CF;</p>
<p>.env.development &#x672C;&#x5730;&#x5F00;&#x53D1;&#x662F;&#x7528;&#x5230;&#x7684;&#x53D8;&#x91CF;&#xFF0C;&#x9ED8;&#x8BA4;&#x6CA1;&#x6709;&#x6B64;&#x6587;&#x4EF6;</p>
<p>.env.preview &#x9884;&#x53D1;&#x5E03;&#x73AF;&#x5883;</p>
<p>.env.testing &#x6D4B;&#x8BD5;&#x73AF;&#x5883;</p>
</blockquote>
<h4 id="envdevelopment">.env.development</h4>
<blockquote>
<p>&#x6B64;&#x6587;&#x4EF6;&#x4E0D;&#x8DDF;&#x968F;git&#x63D0;&#x4EA4;&#x3002;&#x5DF2;&#x7ECF;&#x6DFB;&#x52A0;&#x5230; ignore&#x6587;&#x4EF6;&#x91CC;&#x9762;&#x3002;</p>
<p>&#x672C;&#x5730;&#x7B2C;&#x4E00;&#x6B21;&#x542F;&#x52A8; &#x9700;&#x8981;&#x8FD0;&#x884C;&#x811A;&#x672C; &#x76EE;&#x5F55;&#x5728; <strong>script/generateConfig.sh</strong></p>
<p>&#x901A;&#x8FC7;&#x547D;&#x4EE4; <code>yarn cfg</code> &#x6216; <code>./script/generateConfig.sh</code> &#x4E24;&#x8005;&#x90FD;&#x53EF;&#x4EE5;</p>
</blockquote>
<h4 id="vueconfigjs">vue.config.js</h4>
<blockquote>
<p>webpack &#x5206;&#x7247;</p>
</blockquote>
<pre class="language-"><code class="lang-javascript">config<span class="token punctuation">.</span>optimization<span class="token punctuation">.</span><span class="token function">splitChunks</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
      chunks<span class="token operator">:</span> <span class="token string">&quot;all&quot;</span><span class="token punctuation">,</span>
      minSize<span class="token operator">:</span> <span class="token number">30000</span><span class="token punctuation">,</span> <span class="token comment">//&#x5B57;&#x8282; &#x5F15;&#x5165;&#x7684;&#x6587;&#x4EF6;&#x5927;&#x4E8E;30kb&#x624D;&#x8FDB;&#x884C;&#x5206;&#x5272;</span>
      maxSize<span class="token operator">:</span> <span class="token number">50000</span><span class="token punctuation">,</span> <span class="token comment">//50kb&#xFF0C;&#x5C1D;&#x8BD5;&#x5C06;&#x5927;&#x4E8E;50kb&#x7684;&#x6587;&#x4EF6;&#x62C6;&#x5206;&#x6210;n&#x4E2A;50kb&#x7684;&#x6587;&#x4EF6;</span>
      cacheGroups<span class="token operator">:</span> <span class="token punctuation">{</span>
        libs<span class="token operator">:</span> <span class="token punctuation">{</span>
          name<span class="token operator">:</span> <span class="token string">&quot;chunk-libs&quot;</span><span class="token punctuation">,</span>
          test<span class="token operator">:</span> <span class="token regex">/[\\/]node_modules[\\/]/</span><span class="token punctuation">,</span>
          priority<span class="token operator">:</span> <span class="token number">10</span><span class="token punctuation">,</span>
          chunks<span class="token operator">:</span> <span class="token string">&quot;initial&quot;</span><span class="token punctuation">,</span> <span class="token comment">// only package third parties that are initially dependent</span>
        <span class="token punctuation">}</span><span class="token punctuation">,</span>
        vant<span class="token operator">:</span> <span class="token punctuation">{</span>
          name<span class="token operator">:</span> <span class="token string">&quot;chunk-vant&quot;</span><span class="token punctuation">,</span> <span class="token comment">// split elementUI into a single package</span>
          priority<span class="token operator">:</span> <span class="token number">20</span><span class="token punctuation">,</span> <span class="token comment">// the weight needs to be larger than libs and app or it will be packaged into libs or app</span>
          test<span class="token operator">:</span> <span class="token regex">/[\\/]node_modules[\\/]_?vant(.*)/</span><span class="token punctuation">,</span> <span class="token comment">// in order to adapt to cnpm</span>
        <span class="token punctuation">}</span><span class="token punctuation">,</span>
        commons<span class="token operator">:</span> <span class="token punctuation">{</span>
          name<span class="token operator">:</span> <span class="token string">&quot;chunk-commons&quot;</span><span class="token punctuation">,</span>
          test<span class="token operator">:</span> <span class="token function">resolve</span><span class="token punctuation">(</span><span class="token string">&quot;src/components&quot;</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token comment">// can customize your rules</span>
          minChunks<span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token comment">//  minimum common number</span>
          priority<span class="token operator">:</span> <span class="token number">5</span><span class="token punctuation">,</span>
          reuseExistingChunk<span class="token operator">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span>
        <span class="token punctuation">}</span><span class="token punctuation">,</span>
      <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre>
<h4 id="yarn&#x548C;npm&#x547D;&#x4EE4;&#x5BF9;&#x6BD4;">yarn&#x548C;npm&#x547D;&#x4EE4;&#x5BF9;&#x6BD4;</h4>
<table>
<thead>
<tr>
<th style="text-align:right">npm</th>
<th style="text-align:left">yarn</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:right">npm install</td>
<td style="text-align:left">yarn</td>
</tr>
<tr>
<td style="text-align:right">npm install react --save</td>
<td style="text-align:left">yarn add react</td>
</tr>
<tr>
<td style="text-align:right">npm uninstall react --save</td>
<td style="text-align:left">yarn remove react</td>
</tr>
<tr>
<td style="text-align:right">npm install react --save-dev</td>
<td style="text-align:left">yarn add react --dev</td>
</tr>
<tr>
<td style="text-align:right">npm update --save</td>
<td style="text-align:left">yarn upgrade</td>
</tr>
<tr>
<td style="text-align:right">npm run dev</td>
<td style="text-align:left">yarn dev</td>
</tr>
<tr>
<td style="text-align:right">npm run build</td>
<td style="text-align:left">yarn build</td>
</tr>
</tbody>
</table>
<h4 id="&#x542F;&#x52A8;">&#x542F;&#x52A8;</h4>
<pre class="language-"><code class="lang-shell">yarn dev             #&#x672C;&#x5730;&#x5F00;&#x53D1;&#x542F;&#x52A8; &#x52A0;&#x8F7D; .env.development&#x914D;&#x7F6E;
yarn dev:test         #&#x672C;&#x5730;&#x5F00;&#x53D1; &#x8C03;&#x7528; &#x6D4B;&#x8BD5;&#x73AF;&#x5883;api &#x52A0;&#x8F7D; .env.testing&#x914D;&#x7F6E;
yarn dev:preview     #&#x672C;&#x5730; &#x9884;&#x53D1;&#x73AF;&#x5883;&#x8C03;&#x7528;
yarn prod             #&#x672C;&#x5730; &#x7EBF;&#x4E0A;&#x73AF;&#x5883; &#x8C03;&#x8BD5;
</code></pre>
<h4 id="&#x6253;&#x5305;">&#x6253;&#x5305;</h4>
<pre class="language-"><code class="lang-shell">yarn build:local    #&#x6253;&#x5305;&#x672C;&#x5730;&#x73AF;&#x5883; &#x52A0;&#x8F7D; .env.development&#x914D;&#x7F6E;
yarn build:test     #&#x6D4B;&#x8BD5;&#x73AF;&#x5883;
yarn build:preview  #&#x9884;&#x53D1;
yarn build            #&#x7EBF;&#x4E0A;
</code></pre>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="jsdoc.html" class="navigation navigation-prev " aria-label="Previous page: Jsdoc">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="router.html" class="navigation navigation-next " aria-label="Next page: 路由和侧边栏">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"Webpack","level":"1.4","depth":1,"next":{"title":"路由和侧边栏","level":"1.5","depth":1,"path":"src/router.md","ref":"src/router.md","articles":[]},"previous":{"title":"Jsdoc","level":"1.3","depth":1,"path":"src/jsdoc.md","ref":"src/jsdoc.md","articles":[]},"dir":"ltr"},"config":{"plugins":["expandable-chapters","-lunr","-search","search-pro","-highlight","prism","livereload"],"styles":{"website":"index.css"},"pluginsConfig":{"prism":{"css":["prismjs/themes/prism-tomorrow.css"]},"expandable-chapters":{},"search-pro":{},"livereload":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"Gj","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"introduce","language":"zh-hans","gitbook":"3.2.3","description":"项目搭建、规范、使用示例介绍"},"file":{"path":"src/webpack.md","mtime":"2020-07-29T02:49:42.478Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-07-29T07:02:36.580Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

